package com.ruoyi.procured.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.procured.domain.PaymentRequest;
import com.ruoyi.procured.domain.vo.ProcuredOrderAmountDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

/**
 * 采购订单-申请付款Mapper接口
 *
 * @author 刘广帆
 * @date 2024-10-03
*/
@Mapper
public interface PaymentRequestMapper extends BaseMapper<PaymentRequest> {

    /**
     * 最大可申请多少钱
     * @param ordersId
     * @return
     */
    public ProcuredOrderAmountDTO selectProcuredOrderAmountDueById(String ordersId);
    /**
     * 查询该采购下所申请的记录数据
     * @param paymentRequest
     * @return
     */
    List<PaymentRequest> selectPaymentRequestList(PaymentRequest paymentRequest);
    /**
     * 审核记录
     * @param reviewStatus,deptId,userId,applicant
     * @return
     */
    List<PaymentRequest> selectPaymentRequestByStatus(@Param("reviewStatus")Long reviewStatus, @Param("reviewerUserId")Long reviewerUserId,
                                                      @Param("applicantId")Long applicantId, @Param("applicant")String applicant,
                                                      @Param("isProcess")Boolean isProcess, @Param("reviewerId")Long reviewerId);

    /**
     * 更新申请付款审核状态
     * */
    @Update("UPDATE tb_payment_request SET payment_review_status = #{newStatus},reviewer_user_id = #{reviewerUserId},update_by = #{nickName}," +
            "update_time = NOW()  WHERE payment_request_id = #{paymentRequestId}")
    int updatePaymentReviewStatus(@Param("paymentRequestId")String paymentRequestId,@Param("newStatus") String newStatus,
                                  @Param("nickName") String nickName,@Param("reviewerUserId") Long reviewerUserId);

    /**
     * 通过最新的时间来查询申请单号
     * @return
     */
    public String selectPaymentRequestCode();
    /**
     * 查询申请款总金额
     * @return
     */
    BigDecimal sumAmountByProcuredOrderId(@Param("procuredOrderId") Long procuredOrderId);
    /**
     * 查询申请款退款总金额
     * @return
     */
    BigDecimal sumReturnAmountByProcuredOrderId(@Param("procuredOrderId") Long procuredOrderId);
}




